package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.feast.config.*;
import com.yanqu.road.entity.activity.feast.data.*;
import com.yanqu.road.entity.enums.feast.eFeastType;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 山河乐宴（凡人修仙）
 */
public class ShanHeFeastPb {

    public static ShanHeFeastProto.FeastUserDataTemp.Builder parseUserData(FeastUserData userData, Map<String, FeastUserBehaviorData> behaviorMap,
                                                                           Map<Integer, FeastMissionData> missionMap) {
        if (null == userData) {
            return null;
        }
        ShanHeFeastProto.FeastUserDataTemp.Builder builder = ShanHeFeastProto.FeastUserDataTemp.newBuilder();
        builder.setEnergy(userData.getEnergy());
        builder.setAngerVal(userData.getAngerVal());
        builder.setBreakCount(userData.getBreakCount());
        builder.setLastBreakFailTime(userData.getLastBreakFailTime());
        builder.setLastEnergyRecTime(userData.getLastEnergyRecTime());
        builder.setLastMeditateTime(userData.getLastMeditateTime());
        builder.setPracticeSpeed(userData.getPracticeSpeed());
        builder.setPowerVal(userData.getPowerVal());
        builder.setMaxPowerVal(userData.getMaxPowerVal());
        builder.setStateId(userData.getStateId());
        builder.setTripodLv(userData.getTripodLv());
        builder.setTripodExp(userData.getTripodExp());
        builder.setPracticeVal(userData.getPracticeVal());
        builder.setMountId(userData.getMountId());
        if(userData.getMountId() == 10000){
            builder.setMountId(0);
        }
        builder.setImageId(userData.getImageId());
        builder.setLuckPoint(userData.getLuckPoint());
        builder.setUnreceivedLuckPoint(userData.getUnreceivedLuckPoint());
        builder.addAllItem(parseFeastItemMsgList(userData.getItems()));
        builder.setDrawTimes(userData.getDrawTimes());
        builder.setTempReward(PropertyHelper.parsePropertyToString(userData.getTempReward()));
        if (null != userData.getEquipmentMap()) {
            for (FeastEquipmentData data : userData.getEquipmentMap().values()) {
                ShanHeFeastProto.FeastEquipmentInfoTemp.Builder parseEquipmentInfo = parseFeastEquipmentInfoTemp(data);
                if(parseEquipmentInfo != null) {
                    builder.addEquipmentList(parseEquipmentInfo);
                }
            }
        }
        builder.setProperty(parseFeastPveUserPropertyTemp(userData.getProperty()));
        builder.setTripodEquipment(parseFeastEquipmentInfoTemp(userData.getTripodEquipment()));

        // 地图历练行为统计
        if (null != behaviorMap) {
            for (FeastUserBehaviorData data : behaviorMap.values()) {
                ShanHeFeastProto.FeastMissionBehaviorStatTemp.Builder parseInfo = parseMissionBehaviorTemp(data);
                if(parseInfo != null) {
                    builder.addBehaviorDataList(parseInfo);
                }
            }
        }
        // 地图数据
        if (null != missionMap) {
            for (FeastMissionData data : missionMap.values()) {
                ShanHeFeastProto.FeastMissionInfoTemp.Builder parseInfo = parseMissionInfoTemp(data);
                if(parseInfo != null) {
                    builder.addMissionInfoList(parseInfo);
                }
            }
        }
        builder.setSectId(userData.getSectId());


        return builder;
    }

    public static ShanHeFeastProto.FeastEquipmentInfoTemp.Builder parseFeastEquipmentInfoTemp(FeastEquipmentData testData){
        if(null == testData){
            return null;
        }
        ShanHeFeastProto.FeastEquipmentInfoTemp.Builder msg =  ShanHeFeastProto.FeastEquipmentInfoTemp.newBuilder();
        msg.setEquipmentId(testData.getEquipmentId());
        msg.setBaseLv(testData.getBaseLv());
        msg.setAdvanceLv(testData.getAdvanceLv());
        msg.setSkillLv(testData.getSkillLv());
        msg.setDiffPowerVal(testData.getDiffPowerVal());
        for (Map.Entry<Integer, Long> entry : testData.getAttrAdvanceMap().entrySet()) {
            msg.addAttrAdvanceList(parseFeastAttrInfoTemp(entry.getKey(), entry.getValue()));
        }
        return msg;
    }

    public static ShanHeFeastProto.FeastMissionInfoTemp.Builder parseMissionInfoTemp(FeastMissionData testData){
        if(null == testData){
            return null;
        }
        ShanHeFeastProto.FeastMissionInfoTemp.Builder msg =  ShanHeFeastProto.FeastMissionInfoTemp.newBuilder();
        msg.setMissionId(testData.getMissionId());
        msg.setIsFinish(testData.getIsFinish());
        List<Integer> eventIdList = new ArrayList<>();
        if(testData.getHasExploreGridList() != null) {
            for(FeastGridPositionData data : testData.getHasExploreGridList()){
                if(eventIdList.contains(data.getId())){
                    continue;
                }
                eventIdList.add(data.getId());
                ShanHeFeastProto.FeastGridPositionTemp.Builder tempMsg = parseGridPositionTemp(data);
                if(null != tempMsg){
                    msg.addHasExploreGridList(tempMsg);
                }
            }
        }
        if(testData.getSubsectionGetList() != null) {
            for(int subsectionVal : testData.getSubsectionGetList()){
               msg.addSubsectionGetList(subsectionVal);
            }
        }
        return msg;
    }

    public static ShanHeFeastProto.FeastMissionBehaviorStatTemp.Builder parseMissionBehaviorTemp(FeastUserBehaviorData testData){
        if(null == testData){
            return null;
        }
        ShanHeFeastProto.FeastMissionBehaviorStatTemp.Builder msg =  ShanHeFeastProto.FeastMissionBehaviorStatTemp.newBuilder();
        msg.setMissionId(testData.getMissionId());
        msg.setBehaviorType(testData.getBehaviorType());
        msg.setBehaviorParam(testData.getBehaviorParam());
        msg.setCount(testData.getCount());
        return msg;
    }

    public static ShanHeFeastProto.FeastGridPositionTemp.Builder parseGridPositionTemp(FeastGridPositionData testData){
        if(null == testData){
            return null;
        }
        ShanHeFeastProto.FeastGridPositionTemp.Builder msg =  ShanHeFeastProto.FeastGridPositionTemp.newBuilder();
        msg.setEventId(testData.getId());
        msg.setFinishStatus(testData.getFinishStatus());
        return msg;
    }

    public static ShanHeFeastProto.FeastConfigSyncMsg.Builder parseFeastConfigSyncMsg(ShanHeFeastConfig config, String language) {
        ShanHeFeastProto.FeastConfigSyncMsg.Builder builder =  ShanHeFeastProto.FeastConfigSyncMsg.newBuilder();
        for (FeastPvpPlaceConfig placeConfig : config.getPlaceConfigMap().values()) {
            builder.addPlaceConfig(parseFeastPvpPlaceConfigTemp(placeConfig, language));
        }
        for (FeastStateConfig stateConfig : config.getStateConfigMap().values()) {
            builder.addStateConfig(parseFeastStateConfig(stateConfig, language));
        }
        for (FeastTripodConfig tripodConfig : config.getTripodConfigMap().values()) {
            builder.addTripodConfig(parseFeastTripodConfig(tripodConfig));
        }
        for (FeastEquipmentConfig equipmentConfig : config.getEquipmentConfigMap().values()) {
            builder.addEquipmentConfig(parseFeastEquipmentConfig(equipmentConfig, language));
        }
        for (FeastEventConfig eventConfig : config.getEventConfigMap().values()) {
            builder.addEventConfig(parseFeastEventConfig(eventConfig, language));
        }
        for (FeastNpcConfig npcConfig : config.getNpcConfigMap().values()) {
            builder.addNpcConfig(parseFeastNpcConfig(npcConfig, language));
        }
        for (FeastMissionConfig missionConfig : config.getMissionConfigMap().values()) {
            builder.addMissionConfig(parseFeastMissionConfig(missionConfig, language));
        }
        for (Map<Integer, FeastUpgradeConfig> tempMap : config.getUpgradeConfigMap().values()) {
            for (FeastUpgradeConfig upgradeConfig : tempMap.values()) {
                builder.addUpgradeConfig(parseFeastUpgradeConfig(upgradeConfig));
            }
        }
//        for (FeastPeakConfig pvpPeakConfig : config.getPeakConfigMap().values()) {
//            builder.addPeakConfig(parseFeastPeakConfig(pvpPeakConfig, language));
//        }
        return builder;
    }

    private static ShanHeFeastProto.FeastPvpPlaceConfigTemp.Builder parseFeastPvpPlaceConfigTemp(FeastPvpPlaceConfig placeConfig, String language) {
        if (placeConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastPvpPlaceConfigTemp.Builder builder = ShanHeFeastProto.FeastPvpPlaceConfigTemp.newBuilder();
        builder.setActivityId(placeConfig.getActivityId());
        builder.setId(placeConfig.getId());
//        builder.setType(placeConfig.getType());
//        builder.setName(ServerLanguageMgr.getContent(placeConfig.getName(), language));
//        builder.setLevel(placeConfig.getLevel());
//        builder.setRadius(placeConfig.getRadius());
//        builder.setSeizeScore(placeConfig.getSeizeScore());
//        builder.setSeizeProduce(placeConfig.getSeizeProduce());
        builder.setMapParam(placeConfig.getMapParam());
        builder.setUpDemand(placeConfig.getUpDemand());
        builder.setDownDemand(placeConfig.getDownDemand());
        builder.setSkillScore(placeConfig.getSkillScore());
        builder.setTimeScore(placeConfig.getTimeScore());
        builder.setFirstUpScore(placeConfig.getFirstUpScore());
        builder.setBackgroundSource(placeConfig.getBackgroundSource());
        return builder;
    }

    private static ShanHeFeastProto.FeastStateConfig.Builder parseFeastStateConfig(FeastStateConfig stateConfig, String language) {
        if (stateConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastStateConfig.Builder builder = ShanHeFeastProto.FeastStateConfig.newBuilder();
        builder.setActivityId(stateConfig.getActivityId());
        builder.setId(stateConfig.getId());
        builder.setStateType(stateConfig.getStateType());
        builder.setClassId(stateConfig.getClassId());
        builder.setName(ServerLanguageMgr.getContent(stateConfig.getName(), language));
        builder.setNeedItem(stateConfig.getNeedItem());
        builder.setConsumeItem(stateConfig.getConsumeItem());
        builder.setNeedXianLi(stateConfig.getNeedXianLi());
        builder.setMinXianLi(stateConfig.getMinXianLi());
        builder.setMaxEffect(stateConfig.getMaxEffect());
        builder.setPracticeSpeed(stateConfig.getPracticeSpeed());
        builder.setAttributeAdd(stateConfig.getAttributeAdd());
        builder.setPvpScore(stateConfig.getPvpScore());
        builder.setPvpSpeed(stateConfig.getPvpSpeed());
        return builder;
    }

    private static ShanHeFeastProto.FeastTripodConfig.Builder parseFeastTripodConfig(FeastTripodConfig tripodConfig) {
        if (tripodConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastTripodConfig.Builder builder = ShanHeFeastProto.FeastTripodConfig.newBuilder();
        builder.setActivityId(tripodConfig.getActivityId());
        builder.setLevel(tripodConfig.getLevel());
        builder.setNeedItem(tripodConfig.getNeedItem());
        builder.setStateLimit(tripodConfig.getStateLimit());
        builder.setQualityWeight(tripodConfig.getQualityWeight());
        builder.setTypeRandom(tripodConfig.getTypeRandom());
        builder.setLevelRandom(tripodConfig.getLevelRandom());
        builder.setAdvancedLevelRandom(tripodConfig.getAdvancedLevelRandom());
        builder.setSkillLevelRandom(tripodConfig.getSkillLevelRandom());
        builder.setExtractConsume(tripodConfig.getExtractConsume());
        return builder;
    }

    private static ShanHeFeastProto.FeastEquipmentConfig.Builder parseFeastEquipmentConfig(FeastEquipmentConfig equipmentConfig, String language) {
        if (equipmentConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastEquipmentConfig.Builder builder = ShanHeFeastProto.FeastEquipmentConfig.newBuilder();
        builder.setActivityId(equipmentConfig.getActivityId());
        builder.setId(equipmentConfig.getId());
        builder.setIcon(equipmentConfig.getIcon());
        builder.setType(equipmentConfig.getType());
        builder.setQuality(equipmentConfig.getQuality());
        builder.setName(ServerLanguageMgr.getContent(equipmentConfig.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(equipmentConfig.getDesc(), language));
        builder.setAttribute(equipmentConfig.getAttribute());
        builder.setAdvancedAttribute(equipmentConfig.getAdvancedAttribute());
        builder.setSkillType(equipmentConfig.getSkillType());
        builder.setSkillParameter(equipmentConfig.getSkillParameter());
        builder.setRecoveryReward(equipmentConfig.getRecoveryReward());
        return builder;
    }

    private static ShanHeFeastProto.FeastEventConfig.Builder parseFeastEventConfig(FeastEventConfig eventConfig, String language) {
        if (eventConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastEventConfig.Builder builder = ShanHeFeastProto.FeastEventConfig.newBuilder();
        builder.setActivityId(eventConfig.getActivityId());
        builder.setId(eventConfig.getId());
        builder.setType(eventConfig.getType());
        builder.setEventParameter(eventConfig.getEventParameter());
        builder.setIntroduce(ServerLanguageMgr.getContent(eventConfig.getIntroduce(), language));
        builder.setName(ServerLanguageMgr.getContent(eventConfig.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(eventConfig.getDesc(), language));
        builder.setRewards(eventConfig.getRewards());
        builder.setFailRewards(eventConfig.getFailRewards());
        builder.setIcon(eventConfig.getIcon());
        builder.setXianLi(eventConfig.getXianLi());
        return builder;
    }

    private static ShanHeFeastProto.FeastNpcConfig.Builder parseFeastNpcConfig(FeastNpcConfig npcConfig, String language) {
        if (npcConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastNpcConfig.Builder builder = ShanHeFeastProto.FeastNpcConfig.newBuilder();
        builder.setActivityId(npcConfig.getActivityId());
        builder.setId(npcConfig.getId());
        builder.setType(npcConfig.getType());
        builder.setSmallType(npcConfig.getSmallType());
        builder.setAttributeType(npcConfig.getAttributeType());
        builder.setIcon(npcConfig.getIcon());
        builder.setName(ServerLanguageMgr.getContent(npcConfig.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(npcConfig.getDesc(), language));
        builder.setAttribute(npcConfig.getAttribute());
        builder.setAdvancedAttribute(npcConfig.getAdvancedAttribute());
        builder.setStartParam(npcConfig.getStartParam());
        builder.setEndParam(npcConfig.getEndParam());
        builder.setAttackType(npcConfig.getAttackType());
        builder.setVfxTime(npcConfig.getVfxTime());
        builder.setAttackVfx(npcConfig.getAttackVfx());
        builder.setBodyHeight(npcConfig.getBodyHeight());
        return builder;
    }

    private static ShanHeFeastProto.FeastMissionConfig.Builder parseFeastMissionConfig(FeastMissionConfig missionConfig, String language) {
        if (missionConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastMissionConfig.Builder builder = ShanHeFeastProto.FeastMissionConfig.newBuilder();
        builder.setActivityId(missionConfig.getActivityId());
        builder.setId(missionConfig.getId());
        builder.setName(ServerLanguageMgr.getContent(missionConfig.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(missionConfig.getDesc(), language));
        builder.setStateLimit(missionConfig.getStateLimit());
        builder.setTerrain(missionConfig.getTerrain());
        builder.setType(missionConfig.getType());
        builder.setFloor(missionConfig.getFloor());
        builder.setIcon(missionConfig.getIcon());
        builder.setSubsectionRewards(missionConfig.getSubsectionRewards());
        builder.setBuff(missionConfig.getBuff());
        builder.setConnectDot(missionConfig.getConnectDot());
        return builder;
    }

//    private static ShanHeFeastProto.FeastPeakConfig.Builder parseFeastPeakConfig(FeastPeakConfig peakConfig, String language) {
//        if (peakConfig == null) {
//            return null;
//        }
//        ShanHeFeastProto.FeastPeakConfig.Builder builder = ShanHeFeastProto.FeastPeakConfig.newBuilder();
//        builder.setActivityId(peakConfig.getActivityId());
//        builder.setId(peakConfig.getId());
//        builder.setName(ServerLanguageMgr.getContent(peakConfig.getName(), language));
//        builder.setDesc(ServerLanguageMgr.getContent(peakConfig.getDesc(), language));
//        builder.setIcon(peakConfig.getIcon());
//        builder.setRoomNum(peakConfig.getRoomNum());
//        builder.setPeopleNum(peakConfig.getPeopleNum());
//        builder.setAttributeAdd(peakConfig.getAttributeAdd());
//        return builder;
//    }

    private static ShanHeFeastProto.FeastUpgradeConfig.Builder parseFeastUpgradeConfig(FeastUpgradeConfig upgradeConfig) {
        if (upgradeConfig == null) {
            return null;
        }
        ShanHeFeastProto.FeastUpgradeConfig.Builder builder = ShanHeFeastProto.FeastUpgradeConfig.newBuilder();
        builder.setActivityId(upgradeConfig.getActivityId());
        builder.setId(upgradeConfig.getId());
        builder.setType(upgradeConfig.getType());
        builder.setLevel(upgradeConfig.getLevel());
        builder.setUpgradeAttr(upgradeConfig.getUpgradeAtt());

        return builder;
    }

    public static ShanHeFeastProto.FeastPveUserPropertyTemp.Builder parseFeastPveUserPropertyTemp(FeastPveUserProperty property) {
        if (property == null) {
            return null;
        }
        ShanHeFeastProto.FeastPveUserPropertyTemp.Builder builder = ShanHeFeastProto.FeastPveUserPropertyTemp.newBuilder();
        builder.setAttack(property.getAttrMap().getOrDefault(eFeastType.BattleAttrType.Atk.getValue(), 0L));
        builder.setHp(property.getAttrMap().getOrDefault(eFeastType.BattleAttrType.Hp.getValue(), 0L));
        builder.setAbility(property.getPowerVal());
        for (Map.Entry<Integer, Long> entry : property.getAttrMap().entrySet()) {
            builder.addAttrList(parseFeastAttrInfoTemp(entry.getKey(), entry.getValue()));
        }
        return builder;
    }

    public static ShanHeFeastProto.FeastPvePropertyForCrossTemp.Builder parseFeastPveUserPropertyTemp(FeastUserData userData) {
        if (userData == null) {
            return null;
        }
        ShanHeFeastProto.FeastPvePropertyForCrossTemp.Builder builder = ShanHeFeastProto.FeastPvePropertyForCrossTemp.newBuilder();
        for (Map.Entry<Integer, Long> entry : userData.getProperty().getAttrMap().entrySet()) {
            builder.addAttrList(parseFeastAttrInfoTemp(entry.getKey(), entry.getValue()));
        }
        builder.setImageId(userData.getImageId());
        builder.setPracticeSpeed(userData.getPracticeSpeed());
        builder.setStateId(userData.getStateId());
        builder.setPowerVal(userData.getPowerVal());
        return builder;
    }

    public static ShanHeFeastProto.FeastAttrInfoTemp.Builder parseFeastAttrInfoTemp(int attrId, long attrValue) {
        ShanHeFeastProto.FeastAttrInfoTemp.Builder builder = ShanHeFeastProto.FeastAttrInfoTemp.newBuilder();
        builder.setAttrId(attrId);
        builder.setAttrValue(attrValue);
        return builder;
    }

    public static ShanHeFeastProto.FeastPveChangeDataTemp.Builder parsePveChangeDataTemp(FeastUserData userData){
        if(null == userData){
            return null;
        }
        ShanHeFeastProto.FeastPveChangeDataTemp.Builder changeBuilder = ShanHeFeastProto.FeastPveChangeDataTemp.newBuilder();
        changeBuilder.setLastMeditateTime(userData.getLastMeditateTime());
        changeBuilder.setPowerVal(userData.getPowerVal());
        changeBuilder.setPracticeSpeed(userData.getPracticeSpeed());
        changeBuilder.setPracticeVal(userData.getPracticeVal());
        changeBuilder.setMaxPowerVal(userData.getMaxPowerVal());
        return changeBuilder;
    }

    public static ShanHeFeastProto.FeastBattleObjectTemp.Builder parseBattleObjectTemp(FeastBattleData battleData) {
        if (null == battleData) {
            return null;
        }
        ShanHeFeastProto.FeastBattleObjectTemp.Builder builder = ShanHeFeastProto.FeastBattleObjectTemp.newBuilder();
        builder.setId(battleData.getId());
        builder.setNpcId(battleData.getNpcId());
        builder.setMaxHp(battleData.getMaxHp());
        return builder;
    }

    public static ShanHeFeastProto.FeastBattleEventResultInfoTemp.Builder parseBattleEventResultInfoTemp(FeastBattleResult battleRes){
        if (null == battleRes) {
            return null;
        }
        ShanHeFeastProto.FeastBattleEventResultInfoTemp.Builder builder = ShanHeFeastProto.FeastBattleEventResultInfoTemp.newBuilder();
        builder.setBattleNum(battleRes.getBattleNum());
        builder.setAttackerType(battleRes.getAttackerType());
        builder.setSkillId(battleRes.getSkillId());
        builder.setWinner(battleRes.getWinner());
        builder.setReward(battleRes.getReward());
        builder.setAtkTime(battleRes.getAtkTime());
        builder.setIsBackAtk(battleRes.getBackAtk());
        // 攻击者信息
        ShanHeFeastProto.FeastBattleInfoTemp.Builder infoBuilder = ShanHeFeastProto.FeastBattleInfoTemp.newBuilder();
        infoBuilder.setId(battleRes.getAttacker().getId());
        infoBuilder.setCurHp(battleRes.getAttacker().getCurHp());
        infoBuilder.setHarmValue(battleRes.getAttacker().getHarmValue());
        infoBuilder.setSuckHp(battleRes.getAttacker().getSuckHp());
        infoBuilder.setIsCrit(battleRes.getAttacker().getCrit());
        infoBuilder.setIsStun(battleRes.getAttacker().getStun());
        infoBuilder.setIsDodge(battleRes.getAttacker().getDodge());
        infoBuilder.setAnger(battleRes.getAttacker().getAnger());
        builder.setAttacker(infoBuilder);
        // 防守者信息
        for(FeastBattleInfo infoObj : battleRes.getDefenseList()) {
            infoBuilder = ShanHeFeastProto.FeastBattleInfoTemp.newBuilder();
            infoBuilder.setId(infoObj.getId());
            infoBuilder.setHarmValue(infoObj.getHarmValue());
            infoBuilder.setCurHp(infoObj.getCurHp());
            infoBuilder.setSuckHp(infoObj.getSuckHp());
            infoBuilder.setIsCrit(infoObj.getCrit());
            infoBuilder.setIsStun(infoObj.getStun());
            infoBuilder.setIsDodge(infoObj.getDodge());
//            infoBuilder.setAnger(battleRes.getAttacker().getAnger());
            infoBuilder.setAnger(infoObj.getAnger());
            builder.addDefenseList(infoBuilder);
        }
        return builder;
    }
    public static List<ShanHeFeastProto.FeastItemMsg> parseFeastItemMsgList(Property property) {
        List<ShanHeFeastProto.FeastItemMsg> list = new ArrayList<>();
        for (Map.Entry<Integer, BigInteger> entry : property.getGoods().entrySet()) {
            ShanHeFeastProto.FeastItemMsg.Builder builder = ShanHeFeastProto.FeastItemMsg.newBuilder();
            builder.setItemId(entry.getKey());
            builder.setNum(entry.getValue().longValue());
            list.add(builder.build());
        }
        return list;
    }
}
